import { queryDevicePage } from '@/pages/data/qrcode_device/service';

export default {
  namespace: 'qrcode_device',

  state: {
    list: { data: [] },
    deviceList: { data: [] },
    details: [],
    cond: {},
    subCond: {},
    dict: {},
  },

  effects: {
    *devicePage({ payload }, { call, put, select }) {
      const cond = yield select(state => state.qrcode_device.subCond);
      const params = { ...payload, ...cond };
      const { list = [], total } = yield call(queryDevicePage, params);
      yield put({ type: 'setDevicePage', payload: { list, total } })
    }
  },

  reducers: {
    setSubCond(state, action) {
      return {
        ...state,
        subCond: action.payload
      }
    },
    setDevicePage(state, action) {
      return {
        ...state,
        deviceList: {
          data: action.payload.list,
          dataCnt: action.payload.total
        }
      }
    }
  }
}
